package com.luzhikun.servlet;

import com.luzhikun.service.IUserService;
import com.luzhikun.service.impl.IUserServiceImpl;
import com.luzhikun.util.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "IndexServlet",value = "/indexServlet")
public class IndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 获取前端传来的数据
        IUserService iUserService= (IUserService) ServiceFactory.getService(new IUserServiceImpl());
        String username = request.getParameter("index-username");
        String password = request.getParameter("index-password");
        String phone=request.getParameter("index-phone");
        System.out.println(username);
        System.out.println(password);

        // 用户注册
        iUserService.userIndex(username, password,phone);
        response.sendRedirect(request.getContextPath()+"/index.html");

    }
}
